<template>
	<view class="main">
		<view class="title" style="background-color: rgba(245,245,245,0.75);">
			历史开奖记录
		</view>
		<scroll-view class="ssq-list" scroll-y @scrolltolower="loadMore">
			<view class="item" v-for="item,index in ssqList" :key="index">
				<view class="term">
					<b class="tip">第{{item.term}}期</b>
					<b class="tip">{{item.date}}</b>
				</view>
				<view class="ball">
					<i class="red">{{formatAdd0(item.ball1)}}</i>
					<i class="red">{{formatAdd0(item.ball2)}}</i>
					<i class="red">{{formatAdd0(item.ball3)}}</i>
					<i class="red">{{formatAdd0(item.ball4)}}</i>
					<i class="red">{{formatAdd0(item.ball5)}}</i>
					<i class="red">{{formatAdd0(item.ball6)}}</i>
					<i class="blue">{{formatAdd0(item.ball7)}}</i>
				</view>
			</view>
			<uni-load-more :status="loadMoreStatus" class="more" style="padding-top:15px;padding-bottom: 45px;background-color: rgba(249,249,249,0.75);"></uni-load-more>
		</scroll-view>
	</view>
</template>

<script>
	import request from "@/util/request.js"
	import util from "@/util/util.js"
	import {
		ref,
		onMounted
	} from "vue"
	export default{
		setup() {
			let ssqList = ref([])
			let moreData = ref(false)
			let indexPage = 1
			async function getSsqAct() {
				let g = {}
				g.indexPage = indexPage
				g.pageSize = 20
				g.sDate = '2022-01-01'
				g.eDate = util.formatDate(new Date(), '-')
				// console.log(g)
				let res = await request.getSsq(g)
				if (res.code == 10000) {
					let _data = res.data || []
					let _ssqList = ssqList.value || []
					if (g.indexPage == 1) {
						_ssqList = []
					}
					_ssqList.push.apply(_ssqList, _data)
					ssqList.value = _ssqList
					uni.setStorageSync("ssqData",_ssqList)
					moreData.value = _data.length < g.pageSize ? false : true
					indexPage = g.indexPage + 1
					uni.setStorageSync("ssqIndex",indexPage)
				}
			}
			
			let loadMoreStatus = ref('more')
			function loadMore() {
				loadMoreStatus.value = 'loading'
				if (moreData.value) {
					setTimeout(()=>{
						loadMoreStatus.value = 'more'
						getSsqAct()
					},1000)
				} else {
					loadMoreStatus.value = 'no-more'
				}
			}
			
			function formatAdd0(s) {
				return s*1<10?'0'+s:s
			}
			
			onMounted(()=>{
				const ssqData = uni.getStorageSync("ssqData") || []
				if (util.isNull(ssqData)) {
					getSsqAct()
				} else {
					ssqList.value = ssqData
					indexPage = uni.getStorageSync("ssqIndex") || 1
					moreData.value = true
				}
			})
			
			return{
				ssqList, moreData, loadMoreStatus,
				loadMore, formatAdd0,
			}
		}
	}
</script>
<style lang="scss" scoped src="./com_page.scss"></style>